<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org" xmlns:v-on="http://www.w3.org/1999/xhtml"
      xmlns:v-if="http://www.w3.org/1999/xhtml">
<head th:replace="~{baseui/head :: head}">
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="description" content="动检通智慧云平台"/>
    <meta name="author" content="牧中(上海)物联网科技有限公司"/>
    <link rel="shortcut icon" href="/webjars/images/favicon.png"/>

    <title>牧中畜牧业大数据智慧云平台V1.0</title>


</head>
<body>
<!--顶部一级导航-->
<th:block th:replace="baseui/topheader :: topheader(1)"/>

<!--动检通菜单-->
<div id="topnav" th:replace="djt/partial/topnav :: topnav(3)"></div>


<div id="cl-wrapper">
    <!--左边导航-->
    <th:block th:replace="djt/partial/quarantine_left :: nav(2)"/>

    <div class="container-fluid" id="pcont">
        <div class="cl-mcont">
            <div class="row">
                <div class="col-md-12">
                    <div class="block-flat">
                        <div id="show" class="header from-group"><h3>申报数据管理</h3>
                        </div>

                        <div class="content">
                            <div class="table-responsive">
                                <div id="datatable_wrapper"
                                     class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                                    <div class="row">

                                        <div class="from-group">
                                            <div id="but" class="btn-group col-sm-2" style="width: 180px;float: left">
                                                <input type="hidden" id="hiddate" value="1"/>
                                                <button date-id="but1" type="button"
                                                        class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(1)">
                                                    日
                                                </button>
                                                <button date-id="but2" type="button" class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(2)">
                                                    周
                                                </button>
                                                <button date-id="but3" type="button" class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(3)">
                                                    月
                                                </button>
                                                <button date-id="but4" type="button" class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(4)">
                                                    季
                                                </button>
                                                <button date-id="but6" type="button" class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(6)">
                                                    年
                                                </button>
                                            </div>

                                            <div class="col-sm-2" style="width: 140px">
                                                <div class="input-group date datetime col-md-5 col-xs-7"
                                                     data-min-view="2" data-date-format="yyyy-mm-dd">
                                                    <input id="start" class="form-control" style="width: 90px;"
                                                           size="16"
                                                           type="text" value="" placeholder="开始时间" readonly>
                                                    <span class="input-group-addon btn btn-primary"><span
                                                            class="glyphicon glyphicon-th"></span></span>
                                                </div>
                                            </div>
                                            <div class="col-sm-2" style="width: 140px">
                                                <div class="input-group date datetime col-md-5 col-xs-7"
                                                     data-min-view="2" data-date-format="yyyy-mm-dd">
                                                    <input id="end" class="form-control" style="width: 90px;" size="16"
                                                           type="text" value="" placeholder="结束时间" readonly>
                                                    <span class="input-group-addon btn btn-primary"><span
                                                            class="glyphicon glyphicon-th"></span></span>
                                                </div>


                                            </div>

                                            <!--<option value="">养殖场名称</option>
                                            <option th:each=" breedfactory : ${factoryname}" th:text="${breedfactory.name}"
                                                    th:value="${breedfactory.name}"></option>-->
                                            <div class="col-sm-2" style="width: 150px">
                                                <select id="area" class="select2">
                                                    <option value="全部">所有区域</option>
                                                    <optgroup th:each="cityarea:${areaList}"
                                                              th:label="${cityarea.city}">
                                                        <option th:each="regions:${cityarea.regions}"
                                                                th:text="${regions}" th:value="${regions}"></option>
                                                    </optgroup>

                                                </select>

                                            </div>
                                            <div class="col-sm-2" style="width: 150px">
                                                <select id="type" class="select2">
                                                    <option value="0">动物种类</option>
                                                    <option value="1">猪</option>
                                                    <option value="2">牛</option>
                                                    <option value="3">羊</option>
                                                    <option value="4">家禽</option>

                                                </select>

                                            </div>
                                            <div class="col-sm-2" style="width: 150px">
                                                <select id="status" class="select2">
                                                    <option value="-5">受理状态</option>
                                                    <option value="-1">拒绝</option>
                                                    <option value="-2">驳回</option>
                                                    <option value="-3">不发证</option>
                                                    <option value="0">待提交</option>
                                                    <option value="1">已提交待处理</option>
                                                    <option value="2">已受理待勘察</option>
                                                    <option value="3">已勘察待发证</option>
                                                    <option value="4">已发证</option>
                                                </select>

                                            </div>
                                            <div class="col-sm-2" style="width: 100px">
                                                <button class="btn btn-primary" onclick="SearchBtn()">搜索</button>
                                            </div>

                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="from-gruop">

                                        </div>
                                    </div>
                                    <br/>

                                    <div class="row">
                                        <div class="col-sm-12">

                                            <!-- Table -->
                                            <table id="jqGrid"></table>
                                            <div id="jqGridPager"></div>

                                        </div>
                                    </div>


                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>

<script type="text/javascript" src="/webjars/js/jquery.js"></script>
<script type="text/javascript" src="/webjars/js/jquery.gritter/js/jquery.gritter.js"></script>

<script type="text/javascript" src="/webjars/js/jquery.nanoscroller/jquery.nanoscroller.js"></script>
<script type="text/javascript" src="/webjars/js/behaviour/general.js"></script>
<script src="/webjars/js/jquery.ui/jquery-ui.js" type="text/javascript"></script>

<script type="text/javascript" src="/webjars/js/jquery.nestable/jquery.nestable.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.switch/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="/webjars/js/jquery.select2/select2.min.js" type="text/javascript"></script>
<script src="/webjars/js/skycons/skycons.js" type="text/javascript"></script>
<script src="/webjars/js/bootstrap.slider/js/bootstrap-slider.js" type="text/javascript"></script>
<script type="text/javascript" src="/webjars/js/jquery.niftymodals/js/jquery.modalEffects.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.summernote/dist/summernote.min.js"></script>


<script type="text/javascript" src="/webjars/js/jquery.magnific-popup/dist/jquery.magnific-popup.min.js"></script>


<script src="/webjars/js/behaviour/voice-commands.js"></script>
<script src="/webjars/js/bootstrap/dist/js/bootstrap.min.js"></script>

<script type="text/ecmascript" src="/webjars/jqgrid/js/i18n/grid.locale-cn.js"></script>
<script type="text/ecmascript" src="/webjars/jqgrid/js/jquery.jqGrid.min.js"></script>
<script src="/webjars/js/laydate/laydate.js"></script>
<script src="//vuejs.org/js/vue.min.js"></script>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
<script src="/webjars/js/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
    var PostDatas = {   // 构建查询需要的参数
        area: city(),
        type: $("#type").val(),
        status: $("#status").val()
    };
    $(document).ready(function () {

        App.init();


        //grid
        $("#jqGrid").jqGrid({
            url: '/djt/quarantine/declarIndex',
            mtype: "post",
            postData: PostDatas,
            styleUI: 'Bootstrap',
            datatype: "json",

            autowidth: true,
            colModel: [

                {label: '<span style="text-align: center">序号</span>', name: 'breedReport.id', key: true, width: 50, align: 'center', formatter: showid},
                {label: '<span style="text-align: center">编号</span>', name: 'breedReport.number', width: 150, align: 'center'},
                {label: '<span style="text-align: center">货主</span>', name: 'breedReport.userName', width: 75, align: 'center'},
                {label: '<span style="text-align: center">启运地点</span>', name: 'breedReport.deliverAddress', width: 150, align: 'center'},

                {
                    label: '<span style="text-align: center">到达地点</span>',
                    name: 'breedReport.receiveAddress',
                    width: 150,
                    align: 'center',
                    formatter: showaddress
                },
                {label: '<span style="text-align: center">动物种类</span>', name: 'breedReport.breedType', width: 80, align: 'center', formatter: showtype},
                {label: '<span style="text-align: center">数量及单位</span>', name: 'breedReport.quantity', width: 100, align: 'center', formatter: shownum},
                {label: '<span style="text-align: center">用途</span>', name: 'breedReport.purposeType', width: 75, align: 'center', formatter: showpurposr},
                {label: '<span style="text-align: center">受理状态</span>', name: 'breedReport.status', width: 75, align: 'center', formatter: showstatus},
                {label: '<span style="text-align: center">经办人</span>', name: 'breedReport.owner', width: 75, align: 'center'},
                {label: '<span style="text-align: center">申报时间</span>', name: 'breedReport.createdAt', width: 100, align: 'center', formatter: ShowDate},
                {label: '<span style="text-align: center">详细</span>', width: 200, formatter: ShowOpertator, align: 'center'}
            ],
            viewrecords: true,
            align: 'center',
            height: 350,
            rowNum: 20,
            pager: "#jqGridPager"
        });

    });

    function city() {

        var city = $("#area").val();


        if (city =="全部") {
            var array1 = new Array();
            $("#area option").each(function () {  //遍历所有option
                var txt = $(this).val();   //获取option值
                if (txt != '') {
                    array1.push(txt);  //添加到数组中
                }
            });

            return array1.toString();
        }else {
            var array2 = new Array();
            array2.push(city);
            return array2.toString();
        }

    }
    function ShowDate(cellvalue, options, rowObject) {
        if (cellvalue != null && cellvalue != "") {
            var timestamp4 = new Date(cellvalue);
            var dt = timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
            return dt;
        } else {
            return "";
        }
    }

    /* var start = {
     elem: '#start',
     format: 'YYYY/MM/DD hh:mm:ss',

     max: '2099-06-16 23:59:59', //最大日期
     istime: true,
     istoday: false,
     choose: function (datas) {
     end.min = datas; //开始日选好后，重置结束日的最小日期
     end.start = datas //将结束日的初始值设定为开始日
     }
     };
     var end = {
     elem: '#end',
     format: 'YYYY/MM/DD hh:mm:ss',
     max: '2099-06-16 23:59:59',
     istime: true,
     istoday: false,
     choose: function (datas) {
     start.max = datas; //结束日选好后，重置开始日的最大日期
     }
     };
     laydate(start);
     laydate(end);*/

    /*    function change(num) {
     $("#hiddate").val(num);
     $("button[date-id = but" + num + "]").addClass("active");
     $("button[date-id = but" + num + "]").siblings().removeClass("active");
     }*/

    function SearchBtn() {
        var time1 = $("#start").val();
        var time2 = $("#end").val();
        var area = $("#area").val();
        var type = $("#type").val();
        var status = $("#status").val();
        if (time1 == "") {
            time1 = new Date("2000-01-01 :00:00:00");
        } else {
            time1 = new Date(time1);
        }
        if (time2 == "") {
            time2 = new Date();
        } else {
            time2 = new Date(time2);
        }
        if (area == "") {
            area = null;
        }
        if (type == "") {
            type = 0;
        }
        if (status == "") {
            status = -5;
        }
        var sdata = {   // 构建查询需要的参数
            start: time1,
            end: time2,
            area: city(),
            type: type,
            status: status
        };

        var postData = $("#jqGrid").jqGrid("getGridParam", "postData");

        $.extend(postData, sdata);

        $("#jqGrid").jqGrid("setGridParam", {
            search: true    // (6)将jqGrid的search选项设为true
        }).trigger("reloadGrid", [{page: 1}]);   // (7)重新载入Grid表格，以使上述设置生效

    }

    var SimpleSearch = function (num) {
        var end = new Date();
        var start = new Date();
        switch (num) {
            case 1 :
                start = new Date(new Date() - 24 * 60 * 60 * 1000);
                break;
            case 2:
                start = new Date(new Date() - 7 * 24 * 60 * 60 * 1000);
                break;
            case 3:
                start = new Date(new Date() - 30 * 24 * 60 * 60 * 1000);
                break;
            case 4:
                start = new Date(new Date() - 4 * 30 * 24 * 60 * 60 * 1000);
                break;
            case 5:
                start = new Date(new Date() - 6 * 30 * 24 * 60 * 60 * 1000);
                break;
            case 6:
                start = new Date(new Date() - 12 * 30 * 24 * 60 * 60 * 1000);
                break;
        }
        var sdata = {   // 构建查询需要的参数
            start: start,
            end: end,
            area: city(),
            type: $("#type").val(),
            status: $("#status").val()
        };

        var postData = $("#jqGrid").jqGrid("getGridParam", "postData");

        $.extend(postData, sdata);

        $("#jqGrid").jqGrid("setGridParam", {
            search: true    // (6)将jqGrid的search选项设为true
        }).trigger("reloadGrid", [{page: 1}]);   // (7)重新载入Grid表格，以使上述设置生效

    }

    function showid(cellvalue, options, rowObject) {
        return cellvalue == -1 ? "合计" : cellvalue;

    }
    function showtype(cellvalue, options, rowObject) {
        /*1、猪 2、牛 3、羊 4、家禽*/
        switch (cellvalue) {
            case 1:
                return "猪";
                break;
            case 2:
                return "牛";
                break;
            case 3:
                return "羊";
                break;
            case 4:
                return "家禽";
                break;
            default :
                return "";

        }
    }
    function showstatus(cellvalue, options, rowObject) {
        /*-1：拒绝， -2：驳回，-3：不发证，0：待提交，1：已提交待处理，2：已受理待勘察，3、已勘察待发证，4：已发证*/
        switch (cellvalue) {
            case 1:
                return "已提交待处理";
                break;
            case 2:
                return "已受理待勘察";
                break;
            case 3:
                return "已勘察待发证";
                break;
            case 4:
                return "已发证";
                break;
            case 0:
                return "待提交";
                break;
            case -1:
                return "拒绝";
                break;
            case -2:
                return "驳回";
                break;
            case -3:
                return "不发证";
                break;
            default :
                return "";

        }
    }
    function showpurposr(cellvalue, options, rowObject) {
        /*10:饲养;20:屠宰;30:展览;40:演出;50:比赛;60:其他*/
        switch (cellvalue) {
            case 10:
                return "饲养";
                break;
            case 20:
                return "屠宰";
                break;
            case 30:
                return "展览";
                break;
            case 40:
                return "演出";
                break;
            case 50:
                return "比赛";
                break
            case 60:
                return "其它";
                break
            default :
                return "";

        }
    }
    function shownum(cellvalue, options, rowObject) {
        /*1头 2只 3羽 4克 5 毫升 6 头份 7kg*/
        switch (rowObject.breedReport.unit) {
            case 1:
                return cellvalue + "头";
                break;
            case 2:
                return cellvalue + "只";
                break;
            case 3:
                return cellvalue + "羽";
                break;
            case 4:
                return cellvalue + "克";
                break;
            case 5:
                return cellvalue + "毫升";
                break;
            case 6:
                return cellvalue + "头份";
                break;
            case 7:
                return cellvalue + "kg";
                break;
        }


    }
    function animalSource(data){
        switch (Number(data)) {
            case 10:
                return "家畜家禽";
                break;
            case 20:
                return "人工饲养";
                break;
            case 30:
                return "合法捕获";
                break;

        }

    }
    function showaddress(cellvalue, options, rowObject) {
        if (rowObject.breedReport.receiveAddressMap != null) {
            return rowObject.breedReport.receiveAddressMap.province + rowObject.breedReport.receiveAddressMap.city + rowObject.breedReport.receiveAddressMap.region + rowObject.breedReport.receiveAddressMap.street;
        } else {
            return "";
        }
    }
    function ShowOpertator(cellvalue, options, rowObject) {
        var link;
        var row = JSON.stringify(rowObject);


        link = "<button type='button' class='btn btn-default' id='" + row + "' onclick='select(this.id)'>查看</button><button type='button' class='btn btn-default' id='" + row + "' onclick='delete1(this.id)'>删除</button>";
        return rowObject.id == -1 ? "" : link;
    }

    function select(data) {
        var json = JSON.parse(data);
        var type = showtype(json.breedReport.breedType, null, null);
        var purpose = showpurposr(json.breedReport.purposeType, null, null);
        var timestamp4 = new Date(json.breedReport.createdAt);
        var address = showaddress(null, null, json);
        var dt = timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
        var unit = shownum(json.breedReport.quantity, null, json);
        layui.use(['laypage', 'layer'], function () {
            var $ = layui.jquery, layer = layui.layer;
            layer.open({
                type: 2,
                skin: 'layui-layer-lan',
                area: ['800px', '500px'],
                content: ['/djt/quarantine/managementDetail', 'no'],
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];

                    body.find("#breedFactoryName").text(json.breedReport.breedFactoryName);
                    body.find("#deliverAddress").text(json.breedReport.deliverAddress);
                    body.find("#receiveAddress").text(address);
                    body.find("#userName").text(json.breedReport.userName);
                    body.find("#userMobile").text(json.breedReport.userMobile);
                    body.find("#owner").text(json.breedReport.owner);
                    body.find("#ownerMobile").text(json.breedReport.ownerMobile);
                    body.find("#breedType").text(type);
                    body.find("#animalSource").text(animalSource(json.breedReport.animalSource));
                    body.find("#quantity").text(unit);
                    body.find("#isToLocal").text(json.breedReport.isToLocal==1?'是':'否');
                    body.find("#purposeType").text(purpose);
                    body.find("#createdAt").text(dt);

                }
            });

        });
    }


    function delete1(data) {
        var json = JSON.parse(data);
        layui.use(['laypage', 'layer'], function () {
            var $ = layui.jquery, layer = layui.layer;


            layer.msg('确定删除吗？', {
                time: 60000, //20s后自动关闭
                btn: ['确定', '取消'],
                btnAlign: 'c',
                btn1: function (index, layero) {

                    $.ajax({

                        url: "/djt/quarantine/declarmanageDelete",
                        data: {
                            id: json.breedReport.id,
                            quantity: json.breedReport.quantity,
                            breedId: json.breedReport.breedFactoryId

                        },
                        dataType: "json",
                        success: function (data) {
                            if (data) {
                                layer.msg('删除成功', {
                                    time: 60000, //20s后自动关闭
                                    btn: '确定',
                                    btnAlign: 'c',
                                    btn1: function (index, layero) {
                                        window.location.href ="/djt/quarantine/declarmanage";
                                    }
                                })

                            }else {
                                layer.msg('删除失败请重试', {
                                    time: 60000, //20s后自动关闭
                                    btn: '确定',
                                    btnAlign: 'c',
                                    btn1: function (index, layero) {
                                        window.location.href ="/djt/quarantine/declarmanage";
                                    }
                                })
                            }
                        }
                    })
                }

            })


        });

    }
</script>


</body>
</html>
